package com.wd.elec.controller.bussiness;

import com.wd.elec.domain.AttendGroup;
import com.wd.elec.domain.StaffInfo;
import com.wd.elec.service.IAttendGroupService;
import com.wd.elec.service.IStaffInfoService;
import com.wd.common.annotation.Log;
import com.wd.common.core.controller.BaseController;
import com.wd.common.core.domain.HttpResponse;
import com.wd.common.enums.BusinessType;
import com.wd.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 考勤排班Controller
 * 
 * @author liumingkun125
 * @date 2023-11-07
 */
@RestController
@RequestMapping("/attend/group")
public class AttendGroupController extends BaseController
{
    @Resource
    private IAttendGroupService attendGroupService;

    @Resource
    private IStaffInfoService staffInfoService;

    /**
     * 查询考勤排班列表
     */
    @PreAuthorize("@ss.hasPermi('business:attendGroup:list')")
    @GetMapping("/list")
    public HttpResponse list(AttendGroup attendGroup)
    {
        startPage();
        List<AttendGroup> list = attendGroupService.selectAttendGroupList(attendGroup);
        return HttpResponse.successData(getDataTable(list));
    }

    /**
     * 导出考勤排班列表
     */
    @PreAuthorize("@ss.hasPermi('business:attendGroup:export')")
    @Log(title = "考勤排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttendGroup attendGroup)
    {
        List<AttendGroup> list = attendGroupService.selectAttendGroupList(attendGroup);
        ExcelUtil<AttendGroup> util = new ExcelUtil<>(AttendGroup.class);
        util.exportExcel(response, list, "考勤排班数据");
    }

    /**
     * 获取考勤排班详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:attendGroup:query')")
    @GetMapping(value = "/{groupId}")
    public HttpResponse getInfo(@PathVariable("groupId") Long groupId)
    {
        return successData(attendGroupService.selectAttendGroupByGroupId(groupId));
    }

    /**
     * 查询已分配考勤分组的员工信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:attendGroup:query')")
    @GetMapping(value = "/authStaff/allocatedList")
    public HttpResponse allocatedList(StaffInfo staffInfo)
    {
        startPage();
        List<StaffInfo> list = staffInfoService.selectAllocatedGroupList(staffInfo);
        return HttpResponse.successData(getDataTable(list));
    }

    /**
     * 查询未分配考勤分组的员工信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:attendGroup:query')")
    @GetMapping(value = "/authStaff/unAllocatedList")
    public HttpResponse unAllocatedList(StaffInfo staffInfo)
    {
        startPage();
        List<StaffInfo> list = staffInfoService.selectUnAllocatedGroupList(staffInfo);
        return HttpResponse.successData(getDataTable(list));
    }

    /**
     * 删除员工的考勤班组
     */
    @PreAuthorize("@ss.hasPermi('business:attendGroup:add')")
    @Log(title = "删除员工的考勤班组", businessType = BusinessType.INSERT)
    @PutMapping("/staffGroupCancel")
    public HttpResponse staffGroupCancel(@RequestBody StaffInfo staffInfo)
    {
        return getResult(staffInfoService.staffGroupCancel(staffInfo));
    }


    /**
     * 批量从班组中移除员工
     */
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.GRANT)
    @PutMapping("/cancelAll")
    public HttpResponse cancelAllStaff(Long[] staffIds)
    {
        return getResult(staffInfoService.cancelAllStaffGroup(staffIds));
    }

    /**
     * 批量从班组中移除员工
     */
    @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.GRANT)
    @PutMapping("/authSelectAll")
    public HttpResponse authSelectAll(Long groupId,Long[] staffIds)
    {
        return getResult(staffInfoService.authStaffSelectAll(groupId,staffIds));
    }


    /**
     * 新增考勤排班
     */
    @PreAuthorize("@ss.hasPermi('business:attendGroup:add')")
    @Log(title = "考勤排班", businessType = BusinessType.INSERT)
    @PostMapping
    public HttpResponse add(@RequestBody AttendGroup attendGroup)
    {
        return getResult(attendGroupService.insertAttendGroup(attendGroup));
    }

    /**
     * 修改考勤排班
     */
    @PreAuthorize("@ss.hasPermi('business:attendGroup:edit')")
    @Log(title = "考勤排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public HttpResponse edit(@RequestBody AttendGroup attendGroup)
    {
        return getResult(attendGroupService.updateAttendGroup(attendGroup));
    }

    /**
     * 删除考勤排班
     */
    @PreAuthorize("@ss.hasPermi('business:attendGroup:remove')")
    @Log(title = "考勤排班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public HttpResponse remove(@PathVariable Long[] groupIds)
    {
        return getResult(attendGroupService.deleteAttendGroupByGroupIds(groupIds));
    }
}
